package com.ruoyi.web.controller.member.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.member.MemberBalanceRecordDO;
import com.ruoyi.common.entity.VO.member.MemberBalanceRecordSearchVO;
import com.ruoyi.common.entity.VO.member.MemberBalanceRecordVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

public interface IBackMemberBalanceRecordMapper extends BaseMapper<MemberBalanceRecordDO> {
    List<MemberBalanceRecordVO> searchList(MemberBalanceRecordSearchVO memberBalanceRecordSearchVO);

    @Select("select member_id memberId,new_balance newBalance from member_balance_record where shop_id=#{shopId} and date_format(create_time,'%y%m%d %T') <= date_format(#{endTime},'%y%m%d %T') order by create_time desc")
    List<MemberBalanceRecordDO> searchListForStatic(@Param("shopId") Long shopId,@Param("endTime") String endTime);

    @Select("SELECT SUM(change_balance) FROM member_balance_record WHERE shop_id=#{shopId} and change_type=0 and link_model=5")
    BigDecimal sumBackRechargeAmount(Long shopId);

    @Select("SELECT SUM(change_balance) FROM member_balance_record WHERE shop_id=#{shopId} and change_type=1 and link_model=6")
    BigDecimal sumBackDescAmount(Long shopId);

}
